<template>
  <div class="nothingBox" v-loading="loading">
    <div v-if="tableData.length == 0">
      <el-image :src="require('@/assets/img/nothing.png')"> </el-image>
      <el-button type="primary" @click="$router.push('/eventChange')"
        >暂无内容,点击添加计划</el-button
      >
    </div>

    <!-- <img src="@/assets/img/nothing.png" alt="" /> -->
    <div v-else>
      <div class="listBox">
        <el-card
          shadow="hover"
          class=""
          v-for="(item, index) in tableData"
          :style="{ background: item.color, color: item.textColor }"
          @click.native="slelectEvent(item.id)"
          >{{ item.text }}</el-card
        >
      </div>
      <el-button type="primary" @click="$router.push('/eventChange')"
        >点击添加新计划</el-button
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    selectedDay: {
      type: String,
    },
  },
  data() {
    return {
      tableData: [],
      showForm: false,
      loading: false,
    };
  },
  mounted() {
    this.getData();
    this.$bus.$on("changeSelect", () => {
      this.getData();
    });
  },
  methods: {
    async getData() {
      this.loading = true;
      // let date = (new Date().setHours(0, 0, 0, 0) + "").slice(0, 10);
      let date = (new Date(this.selectedDay).setHours(0, 0, 0, 0) + "").slice(0, 10);
      // console.log(this.selectedDay);
      const { data: res } = await this.$http.post("/calendar/Index/getData", { date });
      this.loading = false;
      if (res.status !== 200) {
        this.$message.error(res.textRequest);
      }

      this.tableData = res.data;
      // console.log(this.tableData);
    },
    slelectEvent(id) {
      this.$router.push({ path: "/eventChange", query: { id } });
      // this.$bus.$emit("selectEvent", id);
    },
  },
};
</script>

<style scoped>
.el-image {
  width: 100%;
  height: 100%;
  margin-top: 5vh;
}
.el-button {
  width: 100%;
}
.el-button .text {
  display: inline-block;
  width: 100%;
}
.listCard:hover {
  cursor: pointer;
  opacity: 0.8;
}
.listBox {
  max-height: 75vh;
  overflow: auto;
  margin-bottom: 5vh;
}
</style>
